/*
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package org.dinky.data.metrics;

import org.dinky.data.annotations.GaugeM;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.With;

@Getter
@Setter
@With
@AllArgsConstructor
@NoArgsConstructor
public class Cpu extends BaseMetrics {
    /** 核心数 */
    private Integer cpuNum;

    /** CPU总的使用率 */
    @GaugeM(name = "cpu.total", description = "Total CPU usage")
    private Double total;

    /** CPU系统使用率 */
    @GaugeM(name = "cpu.sys", description = "CPU system usage")
    private Double sys;

    /** CPU用户使用率 */
    @GaugeM(name = "cpu.used", description = "CPU user usage")
    private Double used;

    /** CPU当前等待率 */
    @GaugeM(name = "cpu.wait", description = "CPU current wait rate")
    private Double wait;

    /** CPU当前空闲率 */
    @GaugeM(name = "cpu.free", description = "CPU current idle rate")
    private Double free;

    public static Cpu of() {
        CpuInfo cpuInfo = OshiUtil.getCpuInfo();
        return BeanUtil.toBean(cpuInfo, Cpu.class);
    }
}
